package com.nit.trash.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.springframework.util.DigestUtils;

import java.util.Date;

public class UserDTO {
    private Long key;
    private Long userId;
    private String userName;
    private Integer roleId;
    private String phone;
    private String idNumber;
    private String password;
    private Integer userType;
    private Integer total;
    private Integer right;
    private Integer wrong;
    private Integer noAnswer;
    private Double accuracy;
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date gmtCreate;

    public UserDTO() {
    }

    public UserDTO(Long key, Long userId, String userName, Integer roleId, String phone, String idNumber, String password, Integer userType, Integer total, Integer right, Integer wrong, Integer noAnswer, Double accuracy, Date gmtCreate) {
        this.key = key;
        this.userId = userId;
        this.userName = userName;
        this.roleId = roleId;
        this.phone = phone;
        this.idNumber = idNumber;
        this.password = password;
        this.userType = userType;
        this.total = total;
        this.right = right;
        this.wrong = wrong;
        this.noAnswer = noAnswer;
        this.accuracy = accuracy;
        this.gmtCreate = gmtCreate;
    }

    public Long getKey() {
        return key;
    }

    public void setKey(Long key) {
        this.key = key;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public Integer getRoleId() {
        return roleId;
    }

    public void setRoleId(Integer roleId) {
        this.roleId = roleId;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getIdNumber() {
        return idNumber;
    }

    public void setIdNumber(String idNumber) {
        this.idNumber = idNumber;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getUserType() {
        return userType;
    }

    public void setUserType(Integer userType) {
        this.userType = userType;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public Integer getRight() {
        return right;
    }

    public void setRight(Integer right) {
        this.right = right;
    }

    public Integer getWrong() {
        return wrong;
    }

    public void setWrong(Integer wrong) {
        this.wrong = wrong;
    }

    public Integer getNoAnswer() {
        return noAnswer;
    }

    public void setNoAnswer(Integer noAnswer) {
        this.noAnswer = noAnswer;
    }

    public Double getAccuracy() {
        return accuracy;
    }

    public void setAccuracy(Double accuracy) {
        this.accuracy = accuracy;
    }

    public Date getGmtCreate() {
        return gmtCreate;
    }

    public void setGmtCreate(Date gmtCreate) {
        this.gmtCreate = gmtCreate;
    }

    public void initNoAnswer() {
        noAnswer = total - right - wrong;
    }

    public void initAccuracy() {
        if (total == 0) {
            accuracy = (double) 0;
        } else {
            accuracy = (double) right / total;
        }
    }

    public static void main(String[] args) {
        System.out.println(DigestUtils.md5DigestAsHex("123456".getBytes()));
    }
}
